package com.fieldchain.ex.fa100.utils.net.tools;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.List;

/**
 * Created by biyunlong on 2016/9/5.
 */
public class GsonApi{
    public static Gson gson;
    public static <T> T parseObject(String json, Class<T> claxx) {
        T t=null;
        if(null==gson){
            gson=new Gson();
        }
        try {
            t=gson.fromJson(json, claxx);
        }catch (Exception e){

        }
        return t;

    }

    public static String toJson(Object obj){
        return new Gson().toJson(obj);
    }


    public static <T> List<T> getList(String json, Class<T> claxx){
        List<T> list= new Gson().fromJson(json, new TypeToken<List<T>>() {}.getType());
        return list;
    }
}
